package com.ruoyi.carowner.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.carowner.domain.CarownerWalletQuestion;
import com.ruoyi.carowner.service.ICarownerWalletQuestionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车主常见问题Controller
 * 
 * @author aa
 * @date 2024-08-13
 */
@RestController
@RequestMapping("/carowner/question")
public class CarownerWalletQuestionController extends BaseController
{
    @Autowired
    private ICarownerWalletQuestionService carownerWalletQuestionService;

    /**
     * 查询车主常见问题列表
     */
    @PreAuthorize("@ss.hasPermi('carowner:question:list')")
    @GetMapping("/list")
    public TableDataInfo list(CarownerWalletQuestion carownerWalletQuestion)
    {
        startPage();
        List<CarownerWalletQuestion> list = carownerWalletQuestionService.selectCarownerWalletQuestionList(carownerWalletQuestion);
        return getDataTable(list);
    }

    /**
     * 导出车主常见问题列表
     */
    @PreAuthorize("@ss.hasPermi('carowner:question:export')")
    @Log(title = "车主常见问题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarownerWalletQuestion carownerWalletQuestion)
    {
        List<CarownerWalletQuestion> list = carownerWalletQuestionService.selectCarownerWalletQuestionList(carownerWalletQuestion);
        ExcelUtil<CarownerWalletQuestion> util = new ExcelUtil<CarownerWalletQuestion>(CarownerWalletQuestion.class);
        util.exportExcel(response, list, "车主常见问题数据");
    }

    /**
     * 获取车主常见问题详细信息
     */
    @PreAuthorize("@ss.hasPermi('carowner:question:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(carownerWalletQuestionService.selectCarownerWalletQuestionById(id));
    }

    /**
     * 新增车主常见问题
     */
    @PreAuthorize("@ss.hasPermi('carowner:question:add')")
    @Log(title = "车主常见问题", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarownerWalletQuestion carownerWalletQuestion)
    {
        return toAjax(carownerWalletQuestionService.insertCarownerWalletQuestion(carownerWalletQuestion));
    }

    /**
     * 修改车主常见问题
     */
    @PreAuthorize("@ss.hasPermi('carowner:question:edit')")
    @Log(title = "车主常见问题", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarownerWalletQuestion carownerWalletQuestion)
    {
        return toAjax(carownerWalletQuestionService.updateCarownerWalletQuestion(carownerWalletQuestion));
    }

    /**
     * 删除车主常见问题
     */
    @PreAuthorize("@ss.hasPermi('carowner:question:remove')")
    @Log(title = "车主常见问题", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(carownerWalletQuestionService.deleteCarownerWalletQuestionByIds(ids));
    }
}
